package flc.ast.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;

import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.PathUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.adapter.MyDrawAdapter;
import flc.ast.databinding.ActivityMyDrawBinding;
import flc.ast.utils.Content;
import stark.common.basic.event.EventStatProxy;

public class MyDrawActivity extends BaseAc<ActivityMyDrawBinding> {

    private MyDrawAdapter myDrawAdapter;
    private List<String> listShow = new ArrayList<>();


    @Override
    protected int onCreate() {
        return R.layout.activity_my_draw;
    }

    @Override
    protected void initView() {
        mDataBinding.ivMyDrawBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        mDataBinding.rvMyDrawList.setLayoutManager(new GridLayoutManager(mContext,2));
        myDrawAdapter=new MyDrawAdapter();
        mDataBinding.rvMyDrawList.setAdapter(myDrawAdapter);
        myDrawAdapter.setOnItemClickListener(this);
    }

    @Override
    protected void onItemClickCallback(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        DrawDetailActivity.imgPath=myDrawAdapter.getItem(position);
        startActivity(DrawDetailActivity.class);
    }

    @Override
    protected void initData() {
    }

    @Override
    protected void onResume() {
        super.onResume();
        getData();
    }

    private void getData(){
        listShow.clear();
        List<File> files = FileUtils.listFilesInDir(PathUtils.getFilesPathExternalFirst() + Content.myDraw);
        if (files.size() > 0) {
            for (File file : files) {
                listShow.add(file.getPath());
            }
        }
        if (listShow.size() > 0) {
            myDrawAdapter.setList(listShow);
            mDataBinding.rvMyDrawList.setVisibility(View.VISIBLE);
            mDataBinding.tvMyDrawNoData.setVisibility(View.GONE);
        } else {
            mDataBinding.rvMyDrawList.setVisibility(View.GONE);
            mDataBinding.tvMyDrawNoData.setVisibility(View.VISIBLE);
        }
    }

}